package com.aforce.entities;

import javax.media.j3d.Alpha;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Group;
import javax.media.j3d.Light;
import javax.media.j3d.Material;
import javax.media.j3d.PointLight;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import org.jdesktop.j3d.examples.collision.Box;
import org.jdesktop.j3d.examples.collision.CollisionDetector;

import com.sun.j3d.utils.geometry.Sphere;

public class SphereEntity extends AbstractEntity
{
	double x_position;
	double y_position;
	double z_position;
	
	Group ogl_group;
	
	public SphereEntity(double x_position, double y_position, double z_position)
	{
		this.x_position = x_position;
		this.y_position = y_position;
		this.z_position = z_position;
		
		ogl_group = createGroup();
	}

	@Override
	public Group getTransformGroup()
	{
		return ogl_group;
	}
	
	private Group createGroup()
	{
		Color3f eColor    = new Color3f(0.0f, 0.0f, 0.0f);
		Color3f sColor    = new Color3f(1.0f, 1.0f, 1.0f);
		Color3f objColor  = new Color3f(0.6f, 0.6f, 0.6f);

		Transform3D t;

		// Create the root of the branch graph
		BranchGroup objRoot = new BranchGroup();

		// Create a Transformgroup to scale all objects so they
		// appear in the scene.
		TransformGroup objScale = new TransformGroup();
		Transform3D t3d = new Transform3D();
		objScale.setTransform(t3d);
		objRoot.addChild(objScale);
		
		// Create a Sphere object, generate one copy of the sphere,
		// and add it into the scene graph.
		Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
		Appearance a = new Appearance();
		m.setLightingEnable(true);
		a.setMaterial(m);
		Sphere sph = new Sphere(0.1f, Sphere.GENERATE_NORMALS, 80, a);
		objScale.addChild(sph);


		// Create transformations for the positional lights
		t = new Transform3D();
		Vector3d lPos1 =  new Vector3d(0.0, 0.0, 2.0);
		t.set(lPos1);

		t = new Transform3D();
		Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
		t.set(lPos2);

		Vector3f lDirect1 = new Vector3f(lPos1);
		Vector3f lDirect2 = new Vector3f(lPos2);
		lDirect1.negate();
		lDirect2.negate();
		
		// Let Java 3D perform optimizations on this scene graph.
		objRoot.compile();

		return objRoot;
	}

}
